package com.entor.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.entor.model.Income;
import com.entor.model.Msg;
import com.entor.model.User;
import com.entor.service.BaseServiceI;
import com.entor.service.ReportService;

@RequestMapping("/inc")
@Controller
public class IncomeController extends BaseController<Income> {
	@Resource(name="incomeService")
	private BaseServiceI<Income> bsii;
	@Resource(name="reportService")
	private ReportService ps;
	
	@RequestMapping("/index")
	public String index(){
		return "/income/index";
	}
	
	@RequestMapping("/handle")
	public String pie(){
		return "/income/handle";
	}
	@RequestMapping("/column")
	public String column(){
		return "/income/column";
	}
	@Override
	public List<Income> find(Income t) {
		return bsii.find(t);
	}
	
	@Override
	public Msg insert(Income t) {
		return bsii.insert(t);
	}
	
	@Override
	public Msg edit(Income t, MultipartFile[] files) {
		return bsii.edit(t);
	}
	
	@RequestMapping("/getCoulmn/{type}")
	@ResponseBody
	public String getColumn(@PathVariable("type") String types){
		return ps.getColumn(types);
	}
	
	
	@RequestMapping("/removea/{id}.coc")
	@ResponseBody
	public Msg remove(@PathVariable(value="id") int id){
		return bsii.remove(id);
	}
	
	@RequestMapping("/aoe")
	public String aoe(HttpServletRequest req){
		String vals = req.getParameter("vals");
		if(vals!=null){
			try {
				vals = new String(vals.getBytes("iso-8859-1"),"utf-8");
			Income in=JSON.parseObject(vals, Income.class);
				req.setAttribute("i", in);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		return "/income/addOrEdit";
	}
}
